export function deleteObjEmpty(object = {}) {
  for (let i in object) {
    let value = object[i];
    let type = Object.prototype.toString.call(value).slice(8, -1);
    switch (type) {
      case 'Array':
      case 'Object':
        deleteObjEmpty(value);
        break;
      default:
    }

    isEmptyValue(value) && delete object[i];
  }
}

export function isEmptyObject(value) {
  for (let i in value) {
    if (!isEmptyValue(value[i])) {
      return false;
    }
  }

  return true;
}

export function isEmptyValue(value) {
  if (value == null) {
    // 等同于 value === undefined || value === null
    return true;
  }
  let type = Object.prototype.toString.call(value).slice(8, -1);
  switch (type) {
    case 'String':
      return !value.trim();
    case 'Array':
      return !value.length;
    case 'Object':
      return isEmptyObject(value); // 普通对象使用 for...in 判断，有 key 即为 false
    default:
      return false; // 其他对象均视作非空
  }
}
